home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-08 | 8.8 KB | 230 lines | [TEXT/MPS ] |
-
-
-
- ; © 1989 Apple Computer, Inc. By Ricardo Batista, Apple Integrated Systems
- ;
- ; ez_load II Version 1.0, March 8 1989
- ; Version 1.1, June 29 1989 unlimited drivers
- ; Version 1.2, July 8, 1991, fixed utablebase bug when table resized.
- ;
- ; This is an INIT that finds an empty slot in the unit table, if there is
- ; no space in the unit table the size of the table is compared to the
- ; pointer of it, because sometimes there is more space but is not counted
- ; and if the space is already there the count of the table is updated. In
- ; the case where there is no space in the table but the table pointer is
- ; used in full another pointer is made with addtitional space for 16 more
- ; drivers and the old table is copied in the new space and the system globals
- ; updated, once a slot is found the driver is loaded who's name is stored
- ; in a string list resource with id -4033, then it looks at a string list resource
- ; id -4034 for the name of a DATA resource and if there is a name for the DATA
- ; resource this is also loaded. The id's are changed according to the empty
- ; driver slot found and the driver is opened. After the driver has been
- ; opened the resources are detached from the resource file. Notice that for
- ; a driver to stay open, the driver and the DATA resource must have the
- ; sysheap and locked bits set in the resource information. From then on it
- ; is up to the driver what it does.
- ;
- ; This version can load any number of drivers, as many as the STR# resource holds
- ; and their DATA resource if they have any.
- ;
- ; INIT resource must be locked
-
- STRING PASCAL
- INCLUDE 'ToolEqu.a'
- INCLUDE 'SysEqu.a'
- INCLUDE 'Traps.a'
-
- SCCLockOut EQU $2600
-
- Frame RECORD 4,DECR
- return DS.L 1
- A6Link DS.L 1
- theID DS.W 1
- theType DS.L 1
- name DS.B 256
- dtheID DS.W 1
- dtheType DS.L 1
- dname DS.B 256
- counter DS.W 1
- rd6 DS.L 1
- rd7 DS.L 1
- fSize EQU *
- ENDR
-
-
- main MAIN
- IMPORT ShowINIT
- link a6,#Frame.fSize ; space for our stack variables
- clr.w Frame.counter(a6) ; initialize our flag to nothing
- move.l d6,Frame.rd6(a6) ; save d6
- move.l d7,Frame.rd7(a6) ; save d7
- BeginSearch
- move.w UnitNtryCnt,d2 ; put number of dce's in d2
- subq.w #1,d2 ; subtract one
- move.w d2,d1 ; put in d1 to multiply
- lsl.w #2,d1 ; multiply by four (shift left 2)
- movea.l UTableBase,a0 ; put unit table base in a0
- SrchLoop
- tst.l (a0,d1.w) ; is there an entry here ?
- beq.s GotSlot ; yes, take it
- subq.l #4,d1 ; substract four, try next down
- subq.w #1,d2 ; substract one to unit number
- cmpi.w #39,d2 ; are we down to the limit ?
- bgt.s SrchLoop ; no ? keep trying
- bra Addentries ; no space huh ? make table bigger
- GotSlot
- clr.l -(sp) ; space for result
- move.l #'STR#',-(sp) ; push resource type
- move.w #-4033,-(sp) ; push id of driver's name to load
- _GetResource ; get it, handle is in stack
- move.l (sp),-(sp) ; duplicate it
- _LoadResource ; make sure it has been loaded
- move.l (sp)+,a0 ; put in a0
- move.l (a0),a0 ; make pointer in a0
- lea Frame.name(a6),a1 ; put destination in a1
- addi.w #1,Frame.counter(a6) ; add one to our list counter
- jsr GetName ; copy the current driver name
- bne end ; end of list ? exit...
- clr.l -(sp) ; space for result
- move.l #'STR#',-(sp) ; push resource type
- move.w #-4034,-(sp) ; push id of driver's data to load
- _GetResource ; get it, handle is in stack
- move.l (sp),-(sp) ; duplicate it
- _LoadResource ; make sure it has been loaded
- move.l (sp)+,a0 ; put in a0
- move.l (a0),a0 ; make pointer in a0
- lea Frame.dname(a6),a1 ; put destination in a1
- jsr GetName ; copy the current data name
- bne end ; end ? exit
- clr.l -(sp) ; space for handle
- move.l #'DRVR',-(sp) ; push driver type
- pea Frame.name(a6) ; push name
- _GetNamedResource ; get it
- move.l (sp)+,d7 ; put driver handle in d7
- beq error ; not found, too bad
- move.w ResErr,d0 ; any errors ?
- bne error ; it's ok then
- move.l d7,-(sp) ; push driver handle
- pea Frame.theID(a6) ; push space fo the id
- pea Frame.theType(a6) ; push space for type
- pea Frame.name(a6) ; push space for name
- _GetResInfo ; get the resource information
- move.l d7,-(sp) ; push driver handle again
- move.w d2,-(sp) ; push the new id
- pea Frame.name(a6) ; push the name
- _SetResInfo ; change the information
- move.b Frame.dname(a6),d0 ; is there a data name to load ?
- beq noData ; no ? ok...
- clr.l -(sp) ; push zero for handle
- move.l #'DATA',-(sp) ; push data
- pea Frame.dname(a6) ; push name of our data
- _GetNamedResource ; load the resource
- move.l (sp)+,d6 ; put handle in d6
- beq error ; not there ? we screwed up
- move.l d6,-(sp) ; push handle
- pea Frame.dtheID(a6) ; push space for id of data
- pea Frame.dtheType(a6) ; push space for type of data
- pea Frame.dname(a6) ; push space for name of data
- _GetResInfo ; get data information
- move.l d6,-(sp) ; push handle again
- move.w d2,d0 ; put slot id in d0
- lsl.w #5,d0 ; shift left
- ori.w #$C000,d0 ; make negative, magic number
- move.w d0,-(sp) ; push new id
- pea Frame.dname(a6) ; push original name
- _SetResInfo ; set the new information
- noData
- move.w d2,-(sp) ; save the unit table id in stack
- clr.w -(sp) ; space for reference number
- pea Frame.name(a6) ; push name of the driver
- _OpenDeskAcc ; open the driver
- move.w (sp)+,d1 ; refnumber in d1
- move.w (sp)+,d2 ; recover unit table id in d2
- muls.w #-1,d1 ; make a positive value (if negative)
- subi.w #1,d1 ; substract 1
- cmp.w d1,d2 ; are these the same ?
- bne error ; no ? the driver didn't load...
- move.l d7,-(sp) ; push handle to driver
- _DetachResource ; now detach it from the resource
- move.b Frame.dname(a6),d0 ; was there a data name loaded ?
- beq end ; no ? exit
- move.l d6,-(sp) ; push handle to driver data
- _DetachResource ; detach it from the resource
- bra.w BeginSearch ; do our job again until the end of list
- end
- move.l Frame.rd6(a6),d6 ; restore d6
- move.l Frame.rd7(a6),d7 ; restore d7
- unlk a6 ; destroy our stack variables
- move.w #-4064,-(sp) ; push id of our icon to show it
- move.w #-1,-(sp) ; push -1 for moveX
- jsr ShowINIT ; show the success icon
- rts ; return
- error
- move.l Frame.rd6(a6),d6 ; restore d6
- move.l Frame.rd7(a6),d7 ; restore d7
- unlk a6 ; destroy stack frame
- move.w #-4033,-(sp) ; push id of our error icon to show it
- move.w #-1,-(sp) ; push -1 for moveX
- jsr ShowINIT ; show the success icon
- rts ; return
- Addentries
- movea.l UTableBase,a0 ; put the unit table pointer in a0
- _GetPtrSize ; get the size of the pointer in d0
- divu.w #4,d0 ; divide by four
- cmp.w UnitNtryCnt,d0 ; is the pointer bigger that specified ?
- bgt.s AddCount ; then the space is already there
- add.w #16,d0 ; add space for 16 more slots
- move.w d0,d1 ; save number of table entries in d1
- mulu.w #4,d0 ; make size of entries in bytes
- _NewPtr sys,clear ; make a new table...
- bne end ; no space ? exit
- move.w SR,-(sp) ; save status register
- move.w #SCCLockOut,SR ; disable interrupts
- movea.l a0,a1 ; put address of new unit table in a1
- movea.l UTableBase,a0 ; put original table in a0
- move.w UnitNtryCnt,d0 ; put original table count in d0
- mulu.w #4,d0 ; get the byte size
- _BlockMove ; copy into the new table
- _DisposPtr ; dispose of the old table
- move.w d1,UnitNtryCnt ; save new number of entries in table
- move.l a1,UTableBase ; save the new table base pointer
- move.w (sp)+,SR ; recover the status register
- bra BeginSearch ; this time we'll find a slot
- AddCount
- move.w d0,UnitNtryCnt ; add the unused slots to the count
- bra BeginSearch ; go find a slot again
-
- DC.B '© 1989 Apple Computer, Inc. By Ricardo Batista'
- ALIGN
-
- GetName
- movem.l d1-d2,-(sp) ; save registers we will use
- move.w (a0),d0 ; put number of list entries in d0
- cmp.w Frame.counter(a6),d0 ; d0- count, d0 < 0 end of list
- blt ListEnd ; end of the list, no more
- move.w Frame.counter(a6),d0 ; put the number of item we want in d0
- adda.l #2,a0 ; point to first string len byte
- moveq #0,d2 ; clear d2, d0 still has string number we want
- FindName
- addi.w #1,d2 ; add one to current string we point to counter
- cmp.w d0,d2 ; is this the string number we want ?
- beq.s CopyName ; if so, then go copy the name and return
- moveq #0,d1 ; clear d1
- move.b (a0),d1 ; put string len byte in d1
- addi.w #1,d1 ; add one for the lenght
- adda.l d1,a0 ; now a0 points to the next string
- bra.s FindName ; go see if this is the one we want
- CopyName
- moveq #30,d0 ; at the most 30 bytes for data name
- _BlockMove ; now we have the data name
- movem.l (sp)+,d1-d2 ; recover registers
- moveq #0,d0 ; set Z flag, list still valid
- rts ; return to caller
- ListEnd
- movem.l (sp)+,d1-d2 ; recover registers
- moveq #1,d0 ; clear Z flag, end of list
- rts ; return to caller
- ENDMAIN
-
- END
-